import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/TokenAuth/NewLoginGetToken',
  Logout = '/services/app/AuthorizationCheck/UnbindAuthUser',
  GetUserInfo = '/services/app/Persons/getUserInfo',
  GetPermCode = '/getPermCode',
}

/**
 * 模块名:登录接口
 * 代码描述:
 * 作者:张泽源
 * 创建时间:2023/11/17 11:42:34
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 模块名:获取用户信息
 * 代码描述:
 * 作者:张泽源
 * 创建时间:2023/11/17 11:42:18
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

/**
 * 模块名:退出登录-清空授权，token
 * 代码描述:
 * 作者:张泽源
 * 创建时间:2023/11/17 11:41:54
 */
export function doLogout() {
  return defHttp.get({ url: Api.Logout });
}
